package cc.openkit.admin.controller.api;

import cc.openkit.admin.model.Area;
import cc.openkit.admin.service.adv.box.AdvBoxService;
import cc.openkit.admin.service.adv.list.AdvListService;
import cc.openkit.admin.service.adv.type.AdvTypeService;
import cc.openkit.admin.service.area.AreaService;
import cc.openkit.admin.util.AppUtil;
import cc.openkit.admin.util.StaticFinalVar;
import cc.openkit.common.KitUtil;
import com.alibaba.fastjson.JSONObject;
import org.apache.log4j.Logger;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * 推荐位的对应接口
 */
@Controller
@Scope("prototype")
@RequestMapping("/apiAdv")
public class ApiAdvController {
    private Logger log = Logger.getLogger(ApiController.class);

    @Resource
    private AdvTypeService advTypeService;
    @Resource
    private AdvListService advListService;
    @Resource
    private AdvBoxService advBoxService;
    @Resource
    private AreaService areaService;

    /**
     * 根据推荐位ID，获取指定条数的数据
     * 验证：APP游客验证
     * @return
     */
    @RequestMapping(value = "/getListByBoxIdAndSize", method = RequestMethod.POST)
    @ResponseBody
    public Object get(HttpServletRequest request){
        if(!AppUtil.isApp(request)){
            return JSONObject.toJSON(KitUtil.returnMap("4001", StaticFinalVar.APP_ERR));
        }

        String boxid = request.getParameter("boxid");
        String size = request.getParameter("size");


        List<Area> areas = areaService.queryAll();
        Map<String, Object> map = KitUtil.returnMap("200", "");
        map.put("kitList",areas);
        return JSONObject.toJSON(map);
    }

}
